//
//  AppDelegate.swift
//  HoneyKeyboard
//
//  Created by Wade on 2025/1/17.
//

import UIKit
import ESTabBarController_swift
@main
class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegate {
    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow.init(frame: UIScreen.main.bounds)
        self.window?.rootViewController = customIrregularityStyle(delegate: self)
        self.window?.makeKeyAndVisible()
        return true
    }


    
     func customIrregularityStyle(delegate: UITabBarControllerDelegate?) -> ESTabBarController {
        let tabBarController = ESTabBarController()
        tabBarController.delegate = delegate
        tabBarController.title = "Irregularity"
        tabBarController.tabBar.shadowImage = UIImage(named: "transparent")
//        tabBarController.tabBar.backgroundImage = UIImage(named: "background_dark")
         tabBarController.tabBar.backgroundColor = .white
        tabBarController.shouldHijackHandler = {
            tabbarController, viewController, index in
            if index == 1 {
                return true
            }
            return false
        }
        tabBarController.didHijackHandler = {
            [weak tabBarController] tabbarController, viewController, index in
            
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
                let alertController = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
                let takePhotoAction = UIAlertAction(title: "Take a photo", style: .default, handler: nil)
                alertController.addAction(takePhotoAction)
                let selectFromAlbumAction = UIAlertAction(title: "Select from album", style: .default, handler: nil)
                alertController.addAction(selectFromAlbumAction)
                let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
                alertController.addAction(cancelAction)
                tabBarController?.present(alertController, animated: true, completion: nil)
            }
        }

//        let stroy = UIStoryboard(name: "Main", bundle: nil)
//        let v1 = stroy.instantiateViewController(withIdentifier: "HKMainVC")
         let v1 = HKMainVC()
        let v2 = HKMenuVC()
        let v3 = HKMyVC()
       
        
        v1.tabBarItem = ESTabBarItem.init(HKTabItemNormalView(), title: "首页", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
         v2.tabBarItem = ESTabBarItem.init(ExampleIrregularityContentView(), title: nil, image: UIImage(named: "photo_verybig"), selectedImage: UIImage(named: "photo_verybig"))
        v3.tabBarItem = ESTabBarItem.init(HKTabItemNormalView(), title: "我的", image: UIImage(named: "favor"), selectedImage: UIImage(named: "favor_1"))
        
        tabBarController.viewControllers = [v1,v2,v3]
       
        return tabBarController
    }
    

}

